$(function() {
	var loading = weui.loading('loading', {
		className: 'custom-classname',
	});
	var result = Model.gift.buyerOrderList({
		type: 11,
	});
	if (!sessionStorage.getItem('hmdj_stopError')) {
		sessionStorage.setItem('hmdj_stopError', true);
	} else {
		if (result.code) {
			Common.fn.formatOutput(result);
			loading.hide();
			return false;
		}
    }
	for (var i = 0; i < result.data[0].gift_order.length; i++) {
        var res = result.data[0].gift_order[i],
            item = '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg inte-index-list inte-order-list-item" data-id="' + res.orderId + '"><div class="weui-media-box__hd"><img class="weui-media-box__thumb" src="' + res.picture + '" alt=""></div><div class="weui-media-box__bd"><h4 class="weui-media-box__title">' + res.name + '</h4><p class="weui-media-box__desc">';
            if(res.free == '不包邮') {
                 item += '邮费 ' + res.postage;
            }else {
			     item += res.free;
		    }
            item += '</p><p class="weui-media-box__desc">剩余：' + res.number + '</p></div><span class="inte-index-list-price">' + res.price + '红米</span></a>';
		$('.order-weui-cells').append(item);
	}
	if (result.data[0].gift_order.length == 0) {
		$('.order-weui-cells').append('<p style="text-align: center; color: #666;">暂无订单</p>');
	}
	// 显示信息数量
	for (var i = 0; i < 4; i++) {
		// 有信息
		if (result.data[0]['num' + parseInt(i + 1)] > 0) {
			var item = '<div class="count-icon">' + result.data[0]['num' + parseInt(i + 1)] + '</div>';
			$('.order-tab-navbar a')
				.eq(i)
				.append(item);
		}
	}
	loading.hide();
});

$(document).on('click', '.inte-order-list-item', function() {
	var orderId = $(this).attr('data-id');
	location.href = 'buyer_detail.html?oid=' + orderId;
});
